package zy.blogs.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import zy.blogs.entity.ParkingLot;
import zy.blogs.entity.Vehicle;

import java.util.List;

@Mapper
public interface VehicleMapper extends BaseMapper<Vehicle> {
    @Results({
            @Result(column = "id",property="id"),
            @Result(column = "parking_lot_id",property = "parkingLot",one =@One(select = "com.zy.mapper.ParkingLotMapper.getById")),
    })
    @Select("select * from vehicle join parking_lot on parking_lot.id=parking_lot_id")
    List<Vehicle> getAll();
    @Insert("insert into vehicle set licence_plate={licencePlate}"+
            ",picUrl=#{picUrl},is_active=#{is_actice}"+
            ",parking_lot_id=#{parkingLot.id}")
    int insert(Vehicle entity);
    @Update("update vehicle set licence_plate=#{licencePlate}"+
            ",picUrl=#{picUrl},is_active"+
            ",parking_lot_id=#{parkingLot.id}")
    int update(Vehicle entity);
    @Select("select * from vehicle join parking_lot"+
            "on parking_lot_id=parking_lot.id"+
            "where vehicle.id=#{id}")
    Vehicle getById(Long id);
}
